
$(function () {
    //页面加载刷新验证码
    var show_num = [];
    draw(show_num);

    //点击图片刷新验证码
    $("#canvas").on('click', function () {
        draw(show_num);
    })

    layui.use('form', function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;
    })

    $("#login_btn").click(function () {
        var data = {};
        data.UserName = $("#username").val();
        data.Password = $("#pwd").val();
        //验证码校验
        var val = $("#code").val().toLowerCase();
        var num = show_num.join("");
        if (val == '') {
            layer.alert('请输入验证码！');
        } else if (val != num) {
            layer.alert('验证码错误！请重新输入！');
            $("#code").val('');
            draw(show_num);
        }
        else {
            $.ajax({
                data: data,
                type: "post",
                url: "/Login/Query",
                success: function (responseResult) {
                    if (responseResult.success) {
                        layer.alert('登录成功！', {
                            title: '提示框',
                            icon: 1,
                        });
                        location.href = "/Home/Index";
                    } else {
                        layer.alert('登录失败！', {
                            title: '提示框',
                            icon: 1,
                        });
                    }
                }
            })
        }

    });


})